package design_mode.代理;

import design_mode.代理.cglib.CarInterceptor;
import design_mode.代理.cglib.Car;
import org.springframework.cglib.proxy.Enhancer;

/**
 * 它可以在运行期扩展Java类与实现Java接口。而CGLIB底层使用的是ASM库。
 *
 * @author dell
 */
public class CgLibMain {


    public static void main(String... args) {
        //生成class文件 保存
//        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "D:\\work\\agentDemo\\target");

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(Car.class);

        CarInterceptor carInterceptor = new CarInterceptor();
        //设置代理前后的Interceptor
        enhancer.setCallback(carInterceptor);


        Car car = (Car) enhancer.create();
        car.driver("川A12131", 1);
        System.out.println();
        car.charging(12d);
    }
}